<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
    response.setHeader("cache-control","public");
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<!-- 创建试卷第三步 -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/common.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/examMng/paperMng.css">
    <style>
        .loader {
            margin-top: 230px !important;
        }
    </style>
    <!--bootstrap基础引用 start-->
    <script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/js/bootstrap.min.js"></script>
    <!--bootstrap基础引用 end-->
    <!--bootstrap-dialog start-->
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.css">
    <script type="text/javascript" src="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.js"></script>
    <!--bootstrap-dialog end-->
    <script src="<%=path%>/static/js/respond.js"></script>


    <!--[if !IE]> -->
    <script type="text/javascript">
        window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
    </script>
    <!-- <![endif]-->

    <script type="text/javascript">
        window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-1.9.1.min.js'>"+"<"+"/script>");
    </script>
</head>
<body>
<!--head begin-->
<div id="header" class="header headbg">
    <div class="container">
        <jsp:include page="../head.jsp" flush="true"/>
    </div>
    <!--head end-->

    <!--body begin-->
    <div class="main-container">
        <div class="container body-box">
            <div class="title-top" style="background: #4c4ca6">
                <p>${paper.title}—<span class="rcolor">试卷配置</span></p>
                <a href="#" onclick="doPost('<%=path%>/paper/pagedata','')" class="retun"><i class="glyphicon glyphicon-arrow-left"></i>返回</a>
            </div>
            <div class="paper-content">
                <div class="outcontent">
                    <!--步骤 begin-->
                    <div class="border_line">
                        <div id="fuelux-wizard" class="row-fluid" data-target="#step-container">
                            <ul class="wizard-steps">
                                <li class="nav_complete">
                                    <span class="step"><i class="glyphicon glyphicon-ok"></i></span>
                                    <span class="title">试卷基本信息</span>
                                </li>

                                <li class="nav_complete">
                                    <span class="step"><i class="glyphicon glyphicon-ok"></i></span>
                                    <span class="title">试卷配置信息</span>
                                </li>

                                <li class="nav_active">
                                    <span class="step">3</span>
                                    <span class="title">试卷发布</span>
                                </li>
                            </ul>
                        </div>
                    </div><!-- /.col -->
                    <!--步骤 end-->
                    <!--试卷发布 begin-->
                    <div class="issue-content">
                        <p class="issue-title">试卷介绍</p>
                        <div class="border blue">
                            <table class="issue-table" cellpadding="0" cellspacing="0" border="0">
                                <tr>
                                    <td class="bcolor">${paper.title}</td>
                                    <td width="15%" align="center" class="bcolor">${paper.score}分</td>
                                    <td width="15%" align="center"><fmt:formatDate value="${paper.createtime}" pattern="yyyy-MM-dd"/></td>
                                    <td width="15%" align="center">${creater}</td>
                                    <td width="15%" align="center"><i class="glyphicon glyphicon-eye-open"></i><a href="javascript:doIssue('/examsys/paper/viewOrEdit','${paperid}')">试卷预览</a></td>
                                </tr>
                            </table>
                        </div>
                        <div class="issue-introduce">
                            <p class="redcolor">试卷介绍：</p>
                            <p>${paper.paperinfo}</p>
                        </div>
                        <div class="issue-introduce">
                            <p class="redcolor">考试题库：</p>
                            <p class="font-weight">${depositoryname}</p>
                        </div>
                        <div class="issue-introduce">
                            <p class="redcolor">题型构成：</p>
                            <div>

                                <c:forEach items="${questiontype}" var="question" varStatus="status">
                                    <div class="xuxian_bg">
											<span class="font-weight pd_title">${status.count}、
												<c:if test="${question.questiontype_id==1}"> 单项选择题 </c:if>
												<c:if test="${question.questiontype_id==2}"> 多项选择题</c:if>
												<c:if test="${question.questiontype_id==3}"> 判断题</c:if>
												（${question.count}道，${question.score}分/题）
											</span>
                                        <span class="text-color pd_scorll">${question.count*question.score}分</span>
                                    </div>
                                </c:forEach>
                            </div>
                        </div>
                    </div>
                    <!--试卷发布 end-->
                    <div class="btnbox">
                        <a class="btn btn-success"href="javascript:history.go(-1);"><i class="glyphicon glyphicon-arrow-left" style="margin-left:0;"></i>上一步</a>
                        <a class="btn btn-info"  onclick="issue()" style="color: #FFFFFF">试卷发布</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--body end-->
    <div class="loader">
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
    </div>
    <!--发布试卷按钮弹窗-->
    <div id="close-cn" class="modal fade" tabindex="-1" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <!--发布试卷header开始-->
                <div class="modal-header">
                    <div class="table-header border-top-radius">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            <span class="white">&times;</span>
                        </button>
                        发布试卷
                    </div>
                </div>
                <!--发布试卷header结束-->
                <!--发布试卷body开始-->
                <div class="modal-body">
                    <div class="text-left">
                        试卷发布成功！
                    </div>
                </div>
                <!--发布试卷body结束-->
                <!--发布试卷footer开始-->
                <div class="modal-footer">
                    <button class="btn btn-sm btn-success" data-dismiss="modal" id="sure-close">
                        <i class="glyphicon glyphicon-ok"></i>确定
                    </button>
                </div>
                <!--发布试卷footer结束-->
            </div>
        </div>
    </div>
    <!--发布试卷按钮弹窗-->
</div>

<script>
    $(function(){
        $('.loader').hide();
        // 试卷列表
        if (${role eq 'master'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else if (${role eq 'trainee'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else {
            $('#topMain').children().eq(4).addClass('active'); // 追加样式;
            // $('#topMain').children().eq(4).children().attr('href', '#');
        }
    })

    //打开模态窗口
    $('#close-cn').modal({backdrop: 'static', keyboard: false , show: false});
    function doPost(to, p) {  // to:提交动作（action）,p:参数
        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = to;
        var myInput = document.createElement("input");
        myInput.setAttribute("name", "id");  // 为input对象设置name
        myInput.setAttribute("value", p);  // 为input对象设置value
        myForm.appendChild(myInput);
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);  // 提交后移除创建的form
    }
    function doIssue(to, p) {  // to:提交动作（action）,p:参数
        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = to;
        var myInput = document.createElement("input");
        myInput.setAttribute("name", "paperid");  // 为input对象设置name
        myInput.setAttribute("value", p);  // 为input对象设置value
        myForm.appendChild(myInput);
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);  // 提交后移除创建的form
    }

    function issue() {
        $('.loader').show();
        var username = $("#username").val();
        var password = $("#password").val();
        var checkCode = $("#checkCode").val();
        $.ajax({
            url : '<%=path%>/paper/doneIssue',
            data: {
                paperid: '${paperid}'
            },
            dataType : "json",
            success : function(data) {
                $('.loader').hide();
                if ("1"==data[0].status) {
                    BootstrapDialog.confirm({
                        title : '提示',
                        message : '试卷发布成功',
                        size : BootstrapDialog.SIZE_SMALL,
                        type : BootstrapDialog.TYPE_DEFAULT,
                        closable : true,
                        btnCancelLabel : '取消',
                        btnOKLabel : '确定',
                        callback:function(result){
                            window.location.href="<%=path%>/paper/pagedata";
                        }
                    });

                } else {
                    BootstrapDialog.confirm({
                        title : '提示',
                        message : '试卷发布失败',
                        size : BootstrapDialog.SIZE_SMALL,
                        type : BootstrapDialog.TYPE_DEFAULT,
                        closable : true,
                        btnCancelLabel : '取消',
                        btnOKLabel : '确定'
                    });
                }
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                BootstrapDialog.confirm({
                    title : '提示',
                    message : '系统错误',
                    size : BootstrapDialog.SIZE_SMALL,
                    type : BootstrapDialog.TYPE_DEFAULT,
                    closable : true,
                    btnCancelLabel : '取消',
                    btnOKLabel : '确定'
                });
            }
        });
    }

    function donePost(to, p) {  // to:提交动作（action）,p:参数
        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = to;
        var myInput = document.createElement("input");
        myInput.setAttribute("name", "id");  // 为input对象设置name
        myInput.setAttribute("value", p);  // 为input对象设置value
        myForm.appendChild(myInput);
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);  // 提交后移除创建的form
    }
</script>
</body>
</html>
